package com.tarena.lbs.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tarena.lbs.base.response.JsonResult;
import com.tarena.lbs.dto.UserGroupParam;
import com.tarena.lbs.dto.UserGroupQuery;
import com.tarena.lbs.entity.UserGroup;
import com.tarena.lbs.service.UserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/usergroup")
@Api(tags = "用户群管理模块")
public class UserGroupController {

  @Autowired
  private UserGroupService userGroupService;

  @PostMapping("/save")
  @ApiOperation(value = "新增用户群", notes = "创建一个新的用户群")
  public JsonResult save(
          @ApiParam(value = "用户群参数", required = true)
          @RequestBody UserGroupParam userGroupParam) {
    log.debug("新增用户群请求: {}", userGroupParam);
    userGroupService.save(userGroupParam);
    return JsonResult.ok();
  }

  @GetMapping("/select")
  @ApiOperation(value = "查询用户群列表", notes = "根据条件查询用户群列表")
  public JsonResult select(
          @ApiParam(value = "用户群查询参数", required = false)
          UserGroupQuery userGroupQuery) {
    log.debug("用户群查询请求: {}", userGroupQuery);
    List<UserGroup> userGroupList = userGroupService.select(userGroupQuery);
    return JsonResult.ok(userGroupList);
  }

  @PostMapping("/delete/{id}")
  @ApiOperation(value = "删除用户群", notes = "根据用户群ID删除对应记录")
  public JsonResult delete(
          @ApiParam(value = "用户群ID", required = true, example = "1")
          @PathVariable Long id) {
    log.debug("删除用户群请求: {}", id);
    userGroupService.delete(id);
    return JsonResult.ok();
  }
}